package com.atues.thread.state;

//测试join方法，想象为插队
public class TestJoin implements Runnable
{
    @Override
    public void run() {
        try {
            Thread.sleep(2000); // 让线程休眠1秒
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
        for (int i = 0; i < 10; i++) {
            System.out.println(Thread.currentThread().getName() + "线程vip " + i);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        TestJoin testJoin = new TestJoin();
        Thread thread = new Thread(testJoin);
        thread.start(); // 启动线程
//        thread.join(); // 等待线程执行完毕
        //主线程
        for (int i = 0; i < 100; i++) {
            if (i == 20) {
                thread.join(); // 插队,该线程会等待testJoin线程执行完毕
            }
            System.out.println("main " + i);
        }
    }


}
